//
//  BYShopCartToolBar.m
//  OCDemo
//
//  Created by zhumuzhi on 2022/2/16.
//

#import "BYShopCartToolBar.h"



@interface BYShopCartToolBar ()

// 标题
@property (nonatomic, strong) UILabel *title;
// 价格
@property (nonatomic, strong) UILabel *price;
// 邮费
@property (nonatomic, strong) UILabel *postage;
// 去支付
@property (nonatomic, strong) UIButton *checkoutButton;

@end

@implementation BYShopCartToolBar

#pragma mark - Event
- (void)checkoutEvent {
    if(self.checkOutBlock) {
        self.checkOutBlock();
    }
}

#pragma mark - Init
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.title];
        [self addSubview:self.price];
        [self addSubview:self.postage];
        [self addSubview:self.checkoutButton];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(kAutoWithSize(10));
        make.top.equalTo(self).offset(kAutoWithSize(10));
    }];
    
    [self.price mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.title.mas_right);
        make.centerY.equalTo(self.title);
    }];
    
    [self.postage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.title.mas_bottom).offset(kAutoWithSize(5));
        make.left.equalTo(self.title);
    }];
    
    [self.checkoutButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(kAutoWithSize(10));
        make.bottom.equalTo(self).offset(-kAutoWithSize(10));
        make.right.equalTo(self).offset(-kAutoWithSize(10));
        make.width.mas_equalTo(kAutoWithSize(150));
    }];
    
    [super layoutSubviews];
}


#pragma mark - LazyGet

- (UILabel *)title {
    if(!_title) {
        _title = [[UILabel alloc] init];
        _title.font = MZFont(12);
        _title.text = @"合计：";
    }
    return _title;
}

- (UILabel *)price {
    if (!_price) {
        _price = [[UILabel alloc] init];
        _price.textColor = PUBLIC_ORANGE_COLOR;
        _price.font = MZBoldFont(14);
        _price.text = @"￥3499";
    }
    return _price;
}

- (UILabel *)postage {
    if (!_postage) {
        _postage = [[UILabel alloc] init];
        _postage.font = MZFont(10);
        _postage.text = @"(全场包邮)";
    }
    return _postage;
}

- (UIButton *)checkoutButton {
    if (!_checkoutButton) {
        _checkoutButton = [[UIButton alloc] init];
        [_checkoutButton setTitle:@"结算" forState:UIControlStateNormal];
        [_checkoutButton setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
        [_checkoutButton setBackgroundColor:PUBLIC_ORANGE_COLOR forState:UIControlStateNormal];
        [_checkoutButton setBackgroundColor:PUBLIC_ORANGE_COLOR forState:UIControlStateSelected];
        [_checkoutButton setBackgroundColor:[UIColor colorWithHexString:@"#BBBBBB"] forState:UIControlStateDisabled];
        [_checkoutButton setViewCornerRadius:kAutoWithSize(8)];
        [_checkoutButton addTarget:self action:@selector(checkoutEvent) forControlEvents:UIControlEventTouchUpInside];
    }
    return _checkoutButton;
}

@end
